package com.youtui.manager.session.impl;

import java.io.Serializable;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.youtui.manager.session.SessionService;

public class LocalSessionServiceImpl implements SessionService {

	@Override
	public void setAttribute(HttpServletRequest request, HttpServletResponse response, String name,
			Serializable value) {
		HttpSession session = request.getSession();
		if (session != null) {
			session.setAttribute(name, value);
		}
	}

	@Override
	public Serializable getAttribute(HttpServletRequest request, HttpServletResponse response, String name) {
		HttpSession session = request.getSession();
		if (session != null) {
			return (Serializable) session.getAttribute(name);
		}
		return null;
	}

	@Override
	public void logout(HttpServletRequest request, HttpServletResponse response) {
		HttpSession session = request.getSession();
		session.invalidate();
	}

	@Override
	public String getSessionId(HttpServletRequest request, HttpServletResponse response) {
		HttpSession session = request.getSession();
		if (session != null) {
			return session.getId();
		}
		return null;
	}

}
